* Replication code for Tomz and Weeks, "Race, Democracy, and Public Support 
* for War," American Political Science Review. This file re-analyzes data 
* from Dafoe, Zhang, and Caughey (DZC). The code processes DZC's replication 
* data and analyzes guesses about race and open-ended responses
* Date: May 9, 2025
version 19.5

*************
* Load data *
*************
	
* Original DZC data from https://doi.org/10.7910/DVN/KVZXE8
* UNF:6:VdxNOxZKU6w5U5l5Azl7+A==
import delimited using ../data/democratic_peace.tab, clear
keep v1 d01 d02 d03 d04 d05 d06 d07 d08 d09 d10 d11 d12 d13 d14 d15 ///
   do_br_fl_71 do_br_fl_173 random4 white_1 white_2

**********************************************************************
* Indicators for expermental conditions: democracy and vignette type *
**********************************************************************

* Democracy vs Non-Democracy
* d01 was baseline, which did not specify democ or any other attributes
gen byte democ = 0 if d01 ~= 1
foreach t in 03 08 09 10 11 13 14 {
	replace democ = 1 if d`t' == 1
}
label define democ 0 "Non-democracy" 1 "Democracy"
label values democ democ

* Vignette type: Basic, Covariate Control, or ENE
gen byte vign = . 
replace vign = 1 if d02 == 1 | d03 == 1 // Basic (no covariate control)
foreach t in 04 05 06 07 08 09 10 11 {
	replace vign = 2 if d`t' == 1 // Covariate control
}
foreach t in 12 13 14 15 {
	replace vign = 3 if d`t' == 1 // ENE (embedded natural experiement)
}
label define vign 1 "Basic" 2 "Covariate Control" 3 "ENE"
label values vign vign

tab democ vign // Matches Dafoe, Zhang, & Caughey 2018 Appendix G2, Table 1

* Restrict to usable cases
drop if democ == . | vign == . // drop baseline & others with missing treatments
drop if vign == 3 // drop ENE vignettes, which differ from std DP experiments

************************
* Analyze race placebo *
************************

// Race placebo question: How likely do you think it is that the majority 
// of the country's population was white (Caucasian)?
// • Very Unlikely (0-20% chance)
// • Unlikely (21-40% chance)
// • Chances About Even (41-60% chance) 
// • Likely (61-80% chance)
// • Very Likely (81-100% chance)
// Answers recorded in either white_1 or white_2

local vlist white_1 white_2
foreach v of varlist `vlist' {
	replace `v' = "" if `v' == "NA"
}
destring `vlist', replace
tab white_1 white_2, miss
gen white_pop = white_1
replace white_pop = white_2 if white_pop == .
label define white_pop 1 "Very unlikely" 2 "Unlikely" 3 "About even" 4 "Likely" 5 "Very Likely"
label values white_pop white_pop
tab white_pop, miss
recode white_pop 1=0 2=0 3=0 4=1 5=1, gen(white_pop2) // binary

capture log close
log using ../output/DZCLog.txt, text nomsg replace
* In original DZC data, percentage of respondents in each regime condition
* who guessed it was likely or very likely that the country was majority white
tab democ white_pop2, row
log off

*********************************************************
* Indicators for question order: when was owrite asked? *
*********************************************************
	
* Half the sample (random4 == 0) got the "Together Placebos" Design.
* Question order for those respondents was recorded in do_br_fl_71
* The other half (random4 == 1) got the "Separted-Placebos" Design
* Question order for those respondents was recorded in do_br_fl_173
rename do_br_fl_71 order0_ // order if random4 == 0
tab order0_
rename do_br_fl_173 order1_ // order if random4 == 1
tab order1_

* Initialize indicator variables for question order
gen byte order_owp1 = . // open write before placebo set 1 (gdp, religion, regions)?
gen byte order_owp2 = . // open write before placebo set 2 (race, other placebos)?
gen byte order_owmm = . // open write before manipulation measure?
label var order_owp1 "Order: open before placebo set 1 (gdp, relig, region)"
label var order_owp2 "Order: open before placebo set 2 (race, oil, etc)"
label var order_owmm "Order: open before manip measure"

* Code ordering for the half who got the "together placebos" design
* Did "Open Write" module come before "FL_84" (placebos)?
* Did "Open Write" module come before "(B) Manipulation Measure"? 
replace order_owp1 = cond(strpos(order0_, "Open Write") < strpos(order0_, "FL_84"), 1, 0) if random4 == 0 & order0_ ~= ""
replace order_owp2 = order_owp1 if random4 == 0 & order0_ ~= "" // all placebos together, so owp2 is same as owp1
replace order_owmm = cond(strpos(order0_, "Open Write") < strpos(order0_, "(B) Manipulation Measure"), 1, 0) if random4 == 0 & order0_ ~= ""

* Code ordering for the half who got the "separated placebos" design
* In separated placebos, placebo set 1 always came before open write
* Did "Open Write" module come before "FL_177" (additional placebos)?
* Did "Open Write" module come before "(B) Manipulation Measure"? 
replace order_owp1 = 0 if random4 == 1 & order1_ ~= "" // by design, placebo set 1 came first
replace order_owp2 = cond(strpos(order1_, "Open Write") < strpos(order1_, "FL_177"), 1, 0) if random4 == 1 & order1_ ~= ""
replace order_owmm = cond(strpos(order1_, "Open Write") < strpos(order1_, "(B) Manipulation Measure"), 1, 0) if random4 == 1 & order1_ ~= ""

* Inspect coding for together placebos design
preserve
keep if order0_ ~= ""
duplicates drop order0_, force
sort order_owp1 order_owp2 order_owmm order0_
list order_owp1 order_owp2 order_owmm order0_
restore

* Inspect coding for separated placebos design
preserve
keep if order1_ ~= ""
duplicates drop order1_, force
sort order_owp1 order_owp2 order_owmm order1_
list order_owp1 order_owp2 order_owmm order1_
restore

* Inspect N's
tab order_owp1 random4, miss
tab order_owp2 random4, miss
tab order_owmm random4, miss

* Indicator for unprompted respondents
gen byte up = cond(order_owp1 == 1 & order_owp2 == 1 & order_owmm == 1, 1, 0)
label var up "Unprompted: owrite before placebos and manip measures"
tab up // % in which owrite came before any placebos or manip measures

* Indicator for partially prompted respondents
gen byte pp = cond(order_owp1 == 1 & order_owp2 == 1, 1, 0) 
label var pp "Partially prompted: owrite before placebos, possibly after manip"
tab pp // percent of data in which owrite came before placebos but possibly after manip measures
tab pp order_owmm

* Inspect N's
tab up pp, miss
tab democ if up 
tab democ if pp

* Trim dataset before merging
keep if pp // Keep only partially prompted or unprompted respondents
keep v1 democ up pp

******************************************************
* Merge-in Tomz-Weeks coding of open-ended responses *
******************************************************

// respondents were asked: "Think about the scenario you read. Write down 
// what you think the country in the scenario is like. Write down at least 
// five things that come to your mind

preserve
import excel using ../data/owrite_coding.xlsx, firstrow clear
tempfile owrite_coding
save `owrite_coding'
restore
merge 1:1 v1 using `owrite_coding', nogenerate

* Approach 1: explicit references to skin color (S) 
gen s = skinexpl
label define simplel 0 "No mention" 1 "'White'" 2 "'Non-white'" 3 "Both"
label values s simplel	

* Approach 2: Add geographic adjectives that could denote ethnicity (SE)
label values ethnic simplel
gen se = s
replace se=ethnic if s==0 // add geographic adjectives
label values se simplel

tab s se if resp==0, miss

*********************
* Analyze open-ends *
*********************

log on

* Rates of responsiveness to owrite prompt (per footnote)
tab resp if up
tab resp if pp

* keep only respondents who were responsive to the owrite prompt
keep if resp==1

* Table 1 (references to skin color only)
tab s democ if up, col miss  // unprompted
tab s democ if pp, col miss  // partially prompted
	
* Table 2 (Skin color plus geographic adjectives)
tab se democ if up, col miss // unprompted
tab se democ if pp, col miss // partially prompted

log close
